home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / Extension Shell 1.5 / Sample Extensions (1.5) / CircleMouse ][ ƒ / ES Handler.c < prev    next >
C/C++ Source or Header  |  1996-04-12  |  7KB  |  310 lines

  1. /*    NAME:
  2.         ES Handler.c
  3.  
  4.     WRITTEN BY:
  5.         Dair Grant
  6.                 
  7.     DESCRIPTION:
  8.         This file contains an ES Handler for use by Extension Shell.
  9.  
  10.     ___________________________________________________________________________
  11. */
  12. //=============================================================================
  13. //        Include files                                                                     
  14. //-----------------------------------------------------------------------------
  15. #include <Gestalt.h>
  16. #include "A4Stuff.h"
  17. #include "SetupA4.h"
  18. #include "ES.h"
  19. #include "CM Constants.h"
  20. #include "ES Handler.h"
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36. //=============================================================================
  37. //        Private function prototypes                                                                     
  38. //-----------------------------------------------------------------------------
  39. void    main(short theMsg, ESParamBlock *theParamBlock);
  40. void    InitialiseParamBlock(void);
  41. void    InitialiseAddrsTable(void);
  42. void    HandleTheError(void);
  43. void    SetUpIcons(short animDelay, short numIcons, short firstIcon);
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59. //=============================================================================
  60. //        Global variables                                                                 
  61. //-----------------------------------------------------------------------------
  62. ESParamBlock    *gTheParamBlock;
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78. //=============================================================================
  79. //        main : Entry point to our code resource.                                                                 
  80. //-----------------------------------------------------------------------------
  81. //        Note :    Extension Shell communicates with us via a message constant,
  82. //                and a pointer to a structure it owns. Our job is to fill in
  83. //                the details in that structure, depending on what it wants us
  84. //                to do.
  85. //-----------------------------------------------------------------------------
  86. void main(short theMsg, ESParamBlock *theParamBlock)
  87. {    long            oldA4;
  88.  
  89.  
  90.  
  91.     // Set up A4 so that we can access our globals
  92. #ifndef powerc
  93.     oldA4 = SetCurrentA4();
  94. #endif
  95.     gTheParamBlock = theParamBlock;
  96.  
  97.  
  98.  
  99.     // Case out on what we have to do
  100.     switch(theMsg) {
  101.         case kInitialiseParamBlock:
  102.              InitialiseParamBlock();
  103.              break;
  104.              
  105.         case kInitialiseAddrsTable:
  106.              InitialiseAddrsTable();
  107.              break;
  108.  
  109.         case kHandleError:
  110.              HandleTheError();
  111.              break;
  112.     
  113.         default:
  114.              ;
  115.     }
  116.  
  117.  
  118.     // Restore A4
  119. #ifndef powerc
  120.     SetA4(oldA4);
  121. #endif
  122. }
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138. //=============================================================================
  139. //        InitialiseParamBlock : Initialises the ParamBlock.                                                                 
  140. //-----------------------------------------------------------------------------
  141. //        Note :    We have three tasks to perform.
  142. //                    • Check to see if we can run
  143. //                    • Set up the icons we want to display
  144. //                    • Set up the code we want installed
  145. //-----------------------------------------------------------------------------
  146. void InitialiseParamBlock(void)
  147. {
  148.  
  149.  
  150.     // Check for System 7. We depend on having System 7, and won't
  151.     // run if we don't have it. If we don't have it, we beep, post
  152.     // an error message, and show our disabled icon(s).
  153.     if (gTheParamBlock->systemVersion < 0x0700)
  154.         {
  155.         // Error details
  156.         gTheParamBlock->beepNow                = true;
  157.         gTheParamBlock->postError            = true;
  158.         gTheParamBlock->errorStringsID        = kErrorStrings;
  159.         gTheParamBlock->errorStringIndex    = kNeedSystemSeven;
  160.  
  161.  
  162.         // Icon details
  163.         SetUpIcons(kDisabledAnimDelay, kMyNumDisabledIcons, kMyFirstDisabledIcon);
  164.         }
  165.     
  166.     
  167.     
  168.     // If a shift key, or the mouse button, is down, we don't load either.
  169.     // We don't post an error, but we do show our disabled icon(s) to let
  170.     // the user know they've turned us off.
  171.     else if ((*gTheParamBlock->IsKeyMouseDown)(kShiftKey, true))
  172.         {
  173.         // Icon details
  174.         SetUpIcons(kDisabledAnimDelay, kMyNumDisabledIcons, kMyFirstDisabledIcon);
  175.         }
  176.     
  177.     
  178.     
  179.     // Otherwise, we're allowed to run. If we had a Control Panel, we
  180.     // would also check to see if our Control Panel had turned us
  181.     // off (by setting some preference resource).
  182.     else
  183.         {
  184.         // Icon details
  185.         SetUpIcons(kEnabledAnimDelay, kMyNumEnabledIcons, kMyFirstEnabledIcon);
  186.         
  187.         
  188.         // We install one VBL task, with no address table.
  189.         gTheParamBlock->installAddressTable                = false;
  190.         gTheParamBlock->numCodeResources                = 1;
  191.  
  192.  
  193.         // Details for a VBL task
  194.         gTheParamBlock->theCodeResources[kCircleVBL].resType    = kCircleVBLResType;
  195.         gTheParamBlock->theCodeResources[kCircleVBL].resID        = kCircleVBLResID;
  196.         gTheParamBlock->theCodeResources[kCircleVBL].codeType    = kVBLTaskType;
  197.         gTheParamBlock->theCodeResources[kCircleVBL].theCodeThing.theVBLTask.vblCount = 1000;
  198.         gTheParamBlock->theCodeResources[kCircleVBL].theCodeThing.theVBLTask.vblPhase = 0;
  199.         }
  200. }
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216. //=============================================================================
  217. //        InitialiseAddrsTable : Initialise the address table.                                                     
  218. //-----------------------------------------------------------------------------
  219. //        Note :    If we requested an address table, Extension Shell calls us back
  220. //                to allow us to initialise any extensions we've made to it.
  221. //
  222. //                This routine will only be called if we request an address
  223. //                table, and is called after the address table is installed,
  224. //                but before any of the items in gTheParamBlock->theCodeResources
  225. //                are processed (since they might need to access the address
  226. //                table).
  227. //
  228. //                We should initialise the magicNumber and versionNumber fields
  229. //                with constants fixed for this build. One possible number for the
  230. //                magicNumber field would be sizeof() our address table structure.
  231. //-----------------------------------------------------------------------------
  232. void InitialiseAddrsTable(void)
  233. {
  234.  
  235. }
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251. //=============================================================================
  252. //        HandleTheError : Handle any errors                                                             
  253. //-----------------------------------------------------------------------------
  254. //        Note :    This routine is called if an error occurred during the
  255. //                installation of the items in gTheParamBlock->theCodeResources.
  256. //
  257. //                If an error occurs we beep, post an error, and request that
  258. //                as much as possible of our code be uninstalled. We also reset
  259. //                the icon details to show our disabled icons.
  260. //-----------------------------------------------------------------------------
  261. void HandleTheError(void)
  262. {
  263.  
  264.  
  265.     // Decide how we want to handle the error
  266.     gTheParamBlock->removeInstalledCode    = true;
  267.     gTheParamBlock->beepNow                = true;
  268.     gTheParamBlock->postError            = true;
  269.     gTheParamBlock->errorStringsID        = kErrorStrings;
  270.  
  271.  
  272.     // Message to display to the user
  273.     gTheParamBlock->errorStringIndex = kUnknownError;
  274.  
  275.  
  276.     // Icon details
  277.     SetUpIcons(kDisabledAnimDelay, kMyNumDisabledIcons, kMyFirstDisabledIcon);
  278. }
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294. //=============================================================================
  295. //        SetUpIcons : Set up our the icon fields in gTheParamBlock.                                                         
  296. //-----------------------------------------------------------------------------
  297. //        Note :    We are passed in the resource ID of the first icon, the number
  298. //                of icons, and a delay for animation. We fill these details
  299. //                in to gTheParamBlock.
  300. //-----------------------------------------------------------------------------
  301. void SetUpIcons(short animDelay, short numIcons, short firstIcon)
  302. {    short        i;
  303.  
  304.  
  305.     gTheParamBlock->animationDelay    = animDelay;
  306.     gTheParamBlock->numIcons        = numIcons;
  307.     for (i = 1; i <= numIcons; i++)
  308.         gTheParamBlock->theIcons[i] = firstIcon + i - 1;
  309. }
  310.